package com.yunqiao.admin.modules.api.controller;

import com.yunqiao.common.utils.PageUtils;
import com.yunqiao.common.utils.R;
import com.yunqiao.service.api.ApplyWithdrawService;
import com.yunqiao.service.api.entity.ApplyWithdrawEntity;
import com.yunqiao.service.api.vo.ApplyWithdrawVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 提现申请
 *
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-02 15:04:03
 */
@RestController
@RequestMapping("api/applywithdraw")
@Api("提现申请表")
public class ApplyWithdrawController {

    @Autowired
    private ApplyWithdrawService applyWithdrawService;

    /**
     * 列表 司机 用户 提现
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:applywithdraw:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = applyWithdrawService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 列表 代理商提现
     */
    @RequestMapping("/listPartner")
    public R listPartner(@RequestParam Map<String, Object> params){
        PageUtils page = applyWithdrawService.queryPagePartner(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("api:applywithdraw:info")
    public R info(@PathVariable("id") Long id){
        ApplyWithdrawVo applyWithdraw = applyWithdrawService.details(id);
        return R.ok().put("applyWithdraw", applyWithdraw);
    }
    /**
     * 信息
     */
    @RequestMapping("/infoPartner/{id}")
    public R infoPartner(@PathVariable("id") Long id){
        ApplyWithdrawVo applyWithdraw = applyWithdrawService.detailsPartner(id);
        return R.ok().put("applyWithdraw", applyWithdraw);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("api:applywithdraw:save")
    public R save(@RequestBody ApplyWithdrawEntity applyWithdraw){
        applyWithdrawService.save(applyWithdraw);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("api:applywithdraw:update")
    public R update(@RequestBody ApplyWithdrawEntity applyWithdraw){
        applyWithdrawService.updateById(applyWithdraw);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("api:applywithdraw:delete")
    public R delete(@RequestBody Integer[] ids){
        applyWithdrawService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @ApiOperation("同意提现 用户 司机")
    @PostMapping("agree/{id}")
    public R agree(@PathVariable Long id) {
        applyWithdrawService.agree(id);
        return R.ok();
    }

    @ApiOperation("拒绝提现 用户 司机")
    @PostMapping("refuse/{id}")
    public R refuse(@PathVariable Long id) {
        applyWithdrawService.refuse(id);
        return R.ok();
    }

    @ApiOperation("代理商提现申请")
    @PostMapping("applyWithdraw")
    public R applyWithdraw(@RequestBody ApplyWithdrawEntity applyWithdrawEntity) {
        applyWithdrawService.applyWithdraw(applyWithdrawEntity);
        return R.ok();
    }
    @ApiOperation("同意提现 代理商")
    @PostMapping("agreePartner/{id}")
    public R agreePartner(@PathVariable Long id) {
        applyWithdrawService.agreePartner(id);
        return R.ok();
    }

    @ApiOperation("拒绝提现 代理商")
    @PostMapping("refusePartner/{id}")
    public R refusePartner(@PathVariable Long id) {
        applyWithdrawService.refusePartner(id);
        return R.ok();
    }
}
